package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.constant.MessageConstant;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.pojo.Setmeal;
import com.itheima.service.ReservationOrderManagemenService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/ReservationOrderManagemen")
public class ReservationOrderManagemenController {

    @Reference
    private ReservationOrderManagemenService reservationOrderManagemenService;

    /*查询预约管理内容*/
    @RequestMapping("/conditionFindSAll")
    public PageResult conditionFindSAll(@RequestBody QueryPageBean queryPageBean) {
        PageResult pageResult = reservationOrderManagemenService.pageQuery(queryPageBean);
        return pageResult;
    }

    /*查询套餐信息*/
    @RequestMapping("/findAll")
    public List<Setmeal> findAll(){
        return reservationOrderManagemenService.findAll();
    }

    /*新增预约信息*/
    @RequestMapping("/add")
    public Result add(@RequestBody Map map, Integer[] setmealIds){
        try {
            reservationOrderManagemenService.add(map,setmealIds);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,MessageConstant.ADD_CHECKITEM_FAIL);
        }
        return new Result(true,MessageConstant.ADD_CHECKITEM_SUCCESS);
    }

    @RequestMapping("/delete")
    public Result delete(int id){
        try {
            reservationOrderManagemenService.deleteOne(id);
            return new Result(true,"删除成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,"您没权限删除");
        }
    }


    //编辑预约信息
    @RequestMapping("/edit")
    public Result edit(Integer[] setmealIds, @RequestBody Map<String, String> map) {
        try {
            reservationOrderManagemenService.edit(setmealIds, map);
            return new Result(true, "预约成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, "预约失败");
        }
    }



    @RequestMapping("/findById")
    public Result findById(Integer id){
        try {
            List<Setmeal> byId = reservationOrderManagemenService.findById(id);
            return new Result(true,MessageConstant.QUERY_ORDER_SUCCESS,byId);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.QUERY_ORDER_FAIL);
        }
    }


    //更改预约状态
    @RequestMapping("/setOrderStatus")
    public Result setOrderStatus(Integer id) {
        try {
            reservationOrderManagemenService.setOrderStatus(id);
            return new Result(true, "更改预约设置成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, "更改预约设置失败");
        }
    }



}

